package com.example.testapplication.ui.login;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;

import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
import androidx.navigation.fragment.NavHostFragment;

import com.example.testapplication.BR;
import com.example.testapplication.R;
import com.example.testapplication.databinding.FragForgetBinding;

import me.goldze.mvvmhabit.base.BaseFragment;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class ForgetFragment extends BaseFragment<FragForgetBinding,ForgetFragmentViewModel> {
    @Override
    public int initContentView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        return R.layout.frag_forget;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initViewObservable() {

        viewModel.uc.pClickEvent.observe(this, new Observer<Integer>() {
            @Override
            public void onChanged(Integer integer) {
                switch (integer){
                    case 1:
                        NavHostFragment.findNavController(ForgetFragment.this).popBackStack();
                        break;
                    //获取验证码
                    case 2:
                        if (viewModel.userName.get().length() != 11) {
                            binding.etPasswordForgetPhone.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.shake_anim));
                            ToastUtils.showShort(R.string.common_phone_input_error);
                            return;
                        }

                        if (true) {
                            ToastUtils.showShort(R.string.common_code_send_hint);
                            binding.cvPasswordForgetCountdown.start();
                            return;
                        }
                        break;
                    case 3:
                        if (viewModel.userName.get().length() != 11) {
                            binding.etPasswordForgetPhone.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.shake_anim));
                            ToastUtils.showShort(R.string.common_phone_input_error);
                            return;
                        }

                        if (viewModel.code.get().length() != getResources().getInteger(R.integer.sms_code_length)) {
                            binding.etPasswordForgetCode.startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.shake_anim));
                            ToastUtils.showShort(R.string.common_code_input_hint);
                            return;
                        }

                        if (true) {
                            NavHostFragment.findNavController(ForgetFragment.this).navigate(R.id.resetPassword);
//                            NavHostFragment.findNavController(ForgetFragment.this).popBackStack();
                            return;
                        }
                        break;
                }

            }
        });
    }
}
